<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui"
                xmlns:fn="http://java.sun.com/jsp/jstl/functions"
                template="/templates/ui.xhtml">

<ui:define name="head">
    <title>打印发票</title>
    <script type="text/javascript" src="My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="js/yxfunc.js"></script>
    <style type="text/css">
        .col-label2 {
            width: 150px;
            font-size: 12px !important;
            text-align: right;
            font-weight: bold;
        }

        .col-input2 {
            font-size: 12px !important;
            text-align: left;
            font-weight: bold;
        }

        .backinv {
            color: red;
        }
    </style>
</ui:define>
<ui:define name="content">
<h:form id="inputform" enctype="multipart/form-data">
<p:messages id="msgs" showSummary="true"/>
<p:panel>
    <h:panelGrid id="dataPanel" columns="2" style="width: 100%;">
        <h:panelGrid columns="4" cellpadding="0" cellspacing="5" border="0" style="width:75%;"
                     columnClasses="col-label2, col-input2, col-label2, col-input2">
            <h:outputLabel value="客户名称:" style="font-weight: bold"/>
            <p:inputText id="custname" value="#{commonAction.invIntDataQryCond.custName}"/>

            <h:outputLabel value="业务类别:" style="font-weight: bold"/>
            <p:selectManyCheckbox id="txntype" value="#{commonAction.invIntDataQryCond.selectTxnTypes}">
                <f:selectItem itemLabel="贷款" itemValue="01"/>
                <f:selectItem itemLabel="贴现" itemValue="02"/>
                <f:selectItem itemLabel="个人" itemValue="03"/>
                <f:selectItem itemLabel="顺延" itemValue="04"/>
            </p:selectManyCheckbox>

            <h:outputLabel value="(基础数据)金额范围起:" style="font-weight: bold"/>
            <p:inputText id="intAmt1" value="#{commonAction.invIntDataQryCond.intAmtSta}"/>

            <h:outputLabel value="(基础数据)金额范围止:" style="font-weight: bold"/>
            <p:inputText id="intAmt2" value="#{commonAction.invIntDataQryCond.intAmtEnd}"/>


            <h:outputLabel value="交易月份起:" style="font-weight: bold"/>
            <p:inputText id="txndate1" size="20" value="#{commonAction.invIntDataQryCond.txnDateSta}"
                         onfocus="var date1 = getMinDateYM();WdatePicker({dateFmt:'yyyy-MM',
                                                minDate:date1,
                                                maxDate:'#F{$dp.$D(\'inputform:txndate2\')}'
                                                })"/>

            <h:outputLabel value="交易月份止:" style="font-weight: bold"/>
            <p:inputText id="txndate2" size="20" value="#{commonAction.invIntDataQryCond.txnDateEnd}"
                         onfocus="var date2 = getMaxDateYM();WdatePicker({dateFmt:'yyyy-MM',
                                                minDate:'#F{$dp.$D(\'inputform:txndate1\')}',
                                                maxDate:date2
                                                })"/>

            <h:outputLabel value="币别:" style="font-weight: bold"/>
            <p:selectOneMenu id="currencytype" value="#{commonAction.invIntDataQryCond.currencyType}">
                <f:selectItem itemLabel="人民币" itemValue="CNY"/>
                <f:selectItem itemLabel="美元" itemValue="USD"/>
                <f:selectItem itemLabel="港币" itemValue="HKD"/>
            </p:selectOneMenu>
        </h:panelGrid>
        <h:panelGrid id="qbtn" columns="1" style="text-align:center;" width="25%">
            <p:commandButton value="检索" style="width:80px;"
                             actionListener="#{commonAction.onQueryInvData}" update="msgs,dtsuccess">
            </p:commandButton>

            <p:commandButton value="开票预览" style="width:80px;"
                             actionListener="#{commonAction.invPreview}" update="msgs,previewtb">
            </p:commandButton>


        </h:panelGrid>
    </h:panelGrid>
</p:panel>
<p:ajaxStatus style="height:18px;text-align:center">
    <f:facet name="start">
        <h:graphicImage value="images/ajaxloadingbar.gif"/>
    </f:facet>
    <f:facet name="complete">
        <h:outputText value=""/>
    </f:facet>
</p:ajaxStatus>
<p:outputLabel style="font-size: 12px !important;font-weight: bold;color: grey;"
               value="业务类别：01-贷款 02-贴现 03-个人 04-顺延 币别：CNY-人民币 USD-美元 HKD-港币"/>
<p:separator/>

<p:contextMenu for="dtsuccess">
    <p:menuitem value="已打印" icon="ui-icon-close"
                actionListener="#{commonAction.invalidInvIntData}"
                update="dtsuccess,previewtb">
    </p:menuitem>
</p:contextMenu>

<p:dataTable id="dtsuccess" value="#{commonAction.invIntDataList}" var="record" rowKey="#{record.pkid}"
             selectionMode="single" selection="#{commonAction.selectedInvIntData}"
             paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
             paginator="true" paginatorPosition="bottom" rows="5" rowsPerPageTemplate="100,50,15,10,5"
             emptyMessage="数据记录为空..." rowStyleClass="#{record.intAmt gt 10000000 ? 'backinv':''}">
    <f:facet name="header">
        发票基础数据信息
    </f:facet>
    <p:column style="text-align:left">
        <f:facet name="header">
            <h:outputText value="客户名称"/>
        </f:facet>
        <h:outputText value="#{record.custName}"/>
    </p:column>

    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="交易日期"/>
        </f:facet>
        <h:outputText value="#{record.txnDate}"/>
    </p:column>

    <p:column style="text-align:right">
        <f:facet name="header">
            <h:outputText value="利息金额"/>
        </f:facet>
        <h:outputText value="#{record.intAmt}">
            <f:convertNumber type="number" pattern="#,###,###,###,##0.00"/>
        </h:outputText>
    </p:column>
    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="业务类别"/>
        </f:facet>
        <h:outputText value="#{record.txnType}"/>
    </p:column>
    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="借据号"/>
        </f:facet>
        <h:outputText value="#{record.iouNum}"/>
    </p:column>

    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="币别"/>
        </f:facet>
        <h:outputText
                value="#{record.currencyType}"/>
    </p:column>
</p:dataTable>

<p:separator/>

<p:contextMenu for="previewtb">
    <p:menuitem value="预览发票明细" icon="ui-icon-search"
                actionListener="#{commonAction.previewInvItem}"
                update="invItemtb" oncomplete="showInvItem.show()">
    </p:menuitem>
</p:contextMenu>

<p:panel id="mypanel">
    <p:commandButton id="batprint" value="批量开票" style="width:80px;margin-left:10px;"
                     actionListener="#{commonAction.batPrint}" onclick="return affirmReInPage();"
                     disabled="#{commonAction.printable}" update="msgs,batprint">
    </p:commandButton>

    <p:commandButton value="停止打印" style="width:80px;margin-left:10px;"
                     actionListener="#{commonAction.stopPrint}" update="previewtb,msgs,batprint">
    </p:commandButton>

    <p:commandButton value="更新数据" style="width:80px;margin-left:10px;"
                     actionListener="#{commonAction.updateData}" update="previewtb,dtsuccess,batprint,msgs">
    </p:commandButton>
</p:panel>
<p:dataTable id="previewtb" height="200" value="#{commonAction.invInvInfoList}"
             selection="#{commonAction.selectedInvInvInfos}"
             var="invInvInfoRecord" rowKey="#{invInvInfoRecord.pkid}"
             paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
             paginator="true" paginatorPosition="bottom" rows="15" rowsPerPageTemplate="100,50,15,10,5"
             emptyMessage="数据记录为空..." rowStyleClass="#{invInvInfoRecord.priceSum gt 10000000 ? 'backinv':''}">
    <f:facet name="header">
        预览发票信息
    </f:facet>
    <p:column selectionMode="multiple" />
    <p:ajax event="rowSelect" listener="#{commonAction.onRowSelected}"/>
    <p:column style="text-align:left">
        <f:facet name="header">
            <h:outputText value="客户名称"/>
        </f:facet>
        <h:outputText value="#{invInvInfoRecord.custName}"/>
    </p:column>

    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="开票日期"/>
        </f:facet>
        <h:outputText value="#{invInvInfoRecord.invDate}"/>
    </p:column>

    <p:column style="text-align:center" sortBy="#{invInvInfoRecord.priceSum}">
        <f:facet name="header">
            <h:outputText value="合计金额"/>
        </f:facet>
        <h:outputText value="#{invInvInfoRecord.priceSum}">
            <f:convertNumber pattern="###,###,###,###,###,###.00"/>
        </h:outputText>
        <f:facet name="footer">
            <h:outputText value="已开发票总额：#{commonAction.currentInvPriceSum}"/>
        </f:facet>
    </p:column>

    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="行业类型"/>
        </f:facet>
        <h:outputText value="#{invInvInfoRecord.busKind}"/>
        <f:facet name="footer">
            <h:outputText value="当前发票代码：#{commonAction.currentInvCode}"/>
        </f:facet>
    </p:column>

    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="收款单位"/>
        </f:facet>
        <h:outputText value="#{invInvInfoRecord.payee}"/>
        <f:facet name="footer">
            <h:outputText value="当前发票号码：#{commonAction.currentInvNo}"/>
        </f:facet>
    </p:column>
    <p:column style="text-align:left">
        <f:facet name="header">
            <h:outputText value="备注"/>
        </f:facet>
        <h:outputText value="#{invInvInfoRecord.remark}"/>
        <f:facet name="footer">
            <h:outputText value="发票总数：#{fn:length(commonAction.invInvInfoList)}"/>
        </f:facet>
    </p:column>

    <f:facet name="footer">
        <h:commandLink>
            <h:outputText value="[导出数据]"/>
            <p:dataExporter type="xls" target="previewtb" fileName="invoiceInfo"/>
        </h:commandLink>
    </f:facet>
</p:dataTable>

<p:dialog id="showInvItem" widgetVar="showInvItem" header="预览发票详情" modal="true" showEffect="drop"
          hideEffect="drop" width="900" height="400">
    <p:outputLabel style="font-size: 12px !important;font-weight: bold;color: grey;"
                   value="项目名称：01-贷款 02-贴现 03-个人 04-顺延"/>
    <p:dataTable id="invItemtb" height="100%" value="#{commonAction.invItemList}"
                 var="invItemrecord"
                 paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                 paginator="true" paginatorPosition="bottom" rows="15" rowsPerPageTemplate="100,50,15,10,5"
                 emptyMessage="数据记录为空...">

        <p:column style="text-align:center">
            <f:facet name="header">
                <h:outputText value="客户名称"/>
            </f:facet>
            <h:outputText value="#{invItemrecord.custName}"/>
        </p:column>

        <p:column style="text-align:center">
            <f:facet name="header">
                <h:outputText value="项目名称"/>
            </f:facet>
            <h:outputText
                    value="#{invItemrecord.itemCode}"/>
        </p:column>

        <p:column style="text-align:center">
            <f:facet name="header">
                <h:outputText value="数量"/>
            </f:facet>
            <h:outputText value="#{invItemrecord.num}"/>
        </p:column>

        <p:column style="text-align:center">
            <f:facet name="header">
                <h:outputText value="单价"/>
            </f:facet>
            <h:outputText value="#{invItemrecord.price}">
                <f:convertNumber type="number" pattern="#,###,###,###,##0.00"/>
            </h:outputText>
        </p:column>
        <p:column style="text-align:center">
            <f:facet name="header">
                <h:outputText value="金额"/>
            </f:facet>
            <h:outputText value="#{invItemrecord.cash}">
                <f:convertNumber type="number" pattern="#,###,###,###,##0.00"/>
            </h:outputText>
        </p:column>
        <p:column style="text-align:center">
            <f:facet name="header">
                <h:outputText value="摘要"/>
            </f:facet>
            <h:outputText value="#{invItemrecord.summary}"/>
        </p:column>
        <f:facet name="footer">
            <h:commandLink>
                <h:outputText value="[导出数据]"/>
                <p:dataExporter type="xls" target="invItemtb" fileName="invItems"/>
            </h:commandLink>
        </f:facet>
    </p:dataTable>
</p:dialog>
</h:form>
</ui:define>
</ui:composition>